package com.itheima.appserver.controller;


import com.itheima.appserver.excepiton.MyException;
import com.itheima.appserver.service.TaohuaService;
import com.itheima.commons.model.vo.ErrorResult;
import com.itheima.commons.model.vo.TaohuaVo;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 用户位置相关API接口
 */
@RestController
@RequestMapping("/peachblossom")
public class TaohuaController {

    @Autowired
    private TaohuaService taohuaService;

    /**
     * 桃花传音-接收语音
     *
     * @return
     */
    @GetMapping
    public ResponseEntity<TaohuaVo> ReceiveVoice() {
        TaohuaVo taohuaVo = this.taohuaService.queryVoice();
        if (taohuaVo == null) {
            throw new MyException(ErrorResult.TodayCount());
        }
        return ResponseEntity.ok(taohuaVo);
    }

    /**
     * 发送传音
     *
     * @param soundFile
     * @return
     */
    @PostMapping
    public ResponseEntity sendVoice(@RequestParam(value = "soundFile", required = false) MultipartFile soundFile) {
        boolean count = this.taohuaService.saveVoice(soundFile);
        if (!count) {
            throw new MyException(ErrorResult.TodayCount());
        }
        return ResponseEntity.ok(null);
    }

}
